package com.esgov.chatbot.support;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * controller响应结果
 * @author Eric Lao
 * @since 2023/02/28 20:00
 */
@Data
@ApiModel(description = "Base数据类型返回")
public class ResponseResult<T> {

    public static final Integer SUCCESS = 1;

    public static final Integer FAIL = 0;

    private ResponseResult(int code, T data, String msg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    /**
     * 响应码
     */
    @ApiModelProperty(value = "响应码，1成功，0失败", name = "code")
    private int code;

    /**
     * 响应主体数据
     */
    @ApiModelProperty(value = "返回数据", name = "data")
    private T data;

    /**
     * 响应信息
     */
    @ApiModelProperty(value = "响应消息", name = "msg")
    private String msg;

    /**
     * 返回成功的响应
     * @return 响应结果
     */
    public static <T> ResponseResult<T> success() {
        return new ResponseResult<>(SUCCESS, null, "操作成功");
    }

    /**
     * 返回成功的响应
     * @param data 响应主体数据
     * @param <T> 响应数据类型
     * @return 响应结果
     */
    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<>(SUCCESS, data, "操作成功");
    }

    /**
     * 返回失败的响应
     * @param msg 响应提示
     * @return 响应结果
     */
    public static <T> ResponseResult<T> fail(String msg) {
        return new ResponseResult<>(FAIL, null, msg);
    }

    /**
     * 返回失败的响应2
     * @param msg 响应提示
     * @param <T> null
     * @return 响应结果
     */
    public static <T> ResponseResult<T> fail2(String msg) {return new ResponseResult<>(FAIL, null, msg);}

    /**
     * 返回失败的响应4
     * @param msg 响应提示
     * @return 响应结果
     */
    public static <T> ResponseResult<T> fail4(String msg) {
        return new ResponseResult<>(-1, null, msg);
    }
}